package org.fast.easy.system.feign.factory;

import lombok.extern.slf4j.Slf4j;
import org.fast.easy.core.domain.result.R;
import org.fast.easy.system.core.domain.vo.SysDictDataVo;
import org.fast.easy.system.feign.service.SystemFeignService;

import org.fast.easy.system.upms.domain.bo.SysDeptBo;
import org.fast.easy.system.upms.domain.vo.SysDeptVo;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

import static org.fast.easy.system.feign.constant.SystemServiceNameConstants.SYSTEM_FEIGN_SERVICE_NAME;

/**
 * 类说明
 *
 * @author YanMing
 * @date 2024/5/15
 */
@Slf4j
@Component
public class SystemFeignFallbackFactory implements FallbackFactory<SystemFeignService>{
    @Override
    public SystemFeignService create(Throwable cause) {
        log.error("{}服务调用失败:{}", SYSTEM_FEIGN_SERVICE_NAME, cause.getMessage());
        return new SystemFeignService()
        {
            @Override
            public R<List<SysDeptVo>> deptList(SysDeptBo dept) {
                return R.fail("获取部门失败:" + cause.getMessage());
            }

            @Override
            public R<List<SysDeptVo>> deptList(Map<String, Object> param) {
                return R.fail("获取部门失败:" + cause.getMessage());
            }

            @Override
            public R<List<SysDeptVo>> deptList(Long parentId) {
                return R.fail("获取部门失败:" + cause.getMessage());
            }

            @Override
            public R<List<SysDictDataVo>> dictDataByType(String dictType) {
                return R.fail("获取字典失败:" + cause.getMessage());
            }
        };
    }
}
